import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import App from './index.vue'
import VueRouter from 'vue-router'
import Axios from 'axios'

Vue.use(ElementUI)
Vue.use(VueRouter) 

const router = new VueRouter({
	mode: 'history',
	routes: [
		{
			path: '/',
			redirect: '/project'//重定向路由
		},
		{
			path: '/project',
			component: resolve => require(['./UI/project.vue'], resolve)
		},
		{
			path: '/backup',
			component: resolve => require(['./UI/backup.vue'], resolve)
		},
    {
      path: '/login',
      component: resolve => require(['./UI/login.vue'], resolve)
    },
    {
      path: '/class',
      component: resolve => require(['./UI/classTable.vue'], resolve)
    },
	]
});

Vue.prototype.$axios = Axios;

Axios.interceptors.request.use(config => {
  console.log('config:');
  console.log(config);
  return config;
},error => {
  console.log(error);
  return error;
});

Axios.interceptors.response.use(response => {
  console.log('res:');
  console.log(response);
  if(response.data.errcode == 1){
    this.$message.warning('请登录！！！');
    router.replace('/login');
  }
  return response;
},error => {
  console.log(error);
  return error;
});

new Vue({
  el: '#app',
  router: router,
  render: h => h(App)
})




